package com.atguigu.service.impl;

import com.atguigu.mapper.AccountMapper;
import com.atguigu.pojo.Account;
import com.atguigu.service.AccountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountMapper accountMapper;


    @Override
    public int deleteAccount(Integer id) {
        return accountMapper.deleteAccount(id);
    }

    @Override
    public int updateAccount(Account account) {
        return accountMapper.updateAccount(account);
    }

    @Override
    public Account queryAccountById(Integer id) {
        return accountMapper.queryAccountById(id);
    }

    /**
     * 方法实现账户数据的添加
     * controller层传递pojo对象Account
     */
    @Transactional
    public int insertAccount(Account account) {
        return accountMapper.insertAccount(account);
    }

    /**
     * 方法实现数据表account分页查询
     * controller层传递当前页数，每页条数
     * 返回PageInfo对象
     */
    public PageInfo<Account> queryAccountByPage(Integer currentPage, Integer pageSize) {
        //分页助手，启动分页
        PageHelper.startPage(currentPage,pageSize);
        //调用持久层，查询数据表
        List<Account> accountList = accountMapper.queryAccountByPage();
        //创建PageInfo对象，构造方法传递集合List
        return new PageInfo<Account>(accountList);
    }
}
